//
//  BKXXDianMingView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/24.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BKXXDianMingView.h"
#import "SYRequestAPI+FuDao.h"

@implementation BKXXDianMingView

- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = [UIColor whiteColor];
    _selectedDataArray = [NSMutableArray new];
    [self addSubview:self.navView];
    [self addSubview:self.searchView];
    [self addSubview:self.tableList];
    [_tableList headerRefreshBlock:^{
        
    }];
    [_tableList fooderRefreshBlock:^{
        
    }];
}
- (void)layout{
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    [_searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(self->_navView.mas_bottom);
        make.height.equalTo(@100);
    }];
    [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0).offset(0);
        make.top.equalTo(self->_searchView.mas_bottom);
        make.bottom.equalTo(@0);
    }];
}

- (ZXFDCCVNav *)navView{
    if (!_navView) {
        ZXFDCCVNav *view = [[ZXFDCCVNav alloc]init];
        view.backgroundColor = MAINBACKCOLOR;
        view.delegate = self;
        view.titleLabe.text = @"补课-点名";
        [view addCommitButton];
        _navView = view;
    }
    return _navView;
}
- (void)submiteClick{
    //提交
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(self.frame.size.width,0, self.frame.size.width, self.frame.size.height);
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (BKXianShangSearchView *)searchView{
    if (!_searchView) {
        BKXianShangSearchView *view = [[BKXianShangSearchView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 100)];
        view.backgroundColor = [UIColor whiteColor];
        _searchView = view;
    }
    return _searchView;
}
- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 144, self.frame.size.width, APP_HEIGHT-84) style:UITableViewStylePlain];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        [tableView registerClass:[BKXXDianMingCell class] forCellReuseIdentifier:@"BKXXDianMingCell"];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableList = tableView;
    }
    return _tableList;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 50;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BKXXDianMingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BKXXDianMingCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[BKXXDianMingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BKXXDianMingCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row%2 == 0) {
        cell.backgroundColor = [UIColor whiteColor];
    }else{
        cell.backgroundColor = [UIColorChange colorwithHexString:@"#F8F8F8"];
    }
    cell.dataArray = @[@"14258",@"姓名",@"Lession One",@"1",@"线下",@"2018-12-01-10 18:00:00",@" "];
    [cell reloadViewLayout];
    cell.indexPath = indexPath;
    cell.block = ^(NSString * _Nonnull index) {
        if (![self->_selectedDataArray containsObject:index]) {
            [self->_selectedDataArray addObject:index];
            self->_navView.commitButton.selected = YES;
        }
    };
    cell.deleteBlock = ^(NSString * _Nonnull index) {
        if ([self->_selectedDataArray containsObject:index]) {
            [self->_selectedDataArray removeObject:index];
        }
        if (self->_selectedDataArray.count<=0) {
            self->_navView.commitButton.selected = NO;
        }else{
            self->_navView.commitButton.selected = YES;
        }
    };
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //NSLog(@"点击了cell");
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (!_titleView) {
        _titleView = [[BKXXCellHeaderView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44) andArray:@[@"学号",@"姓名",@"教材",@"课时",@"类型",@"时间",@"出勤"]];
        _titleView.backgroundColor = CONTENTBACKCOLOR;
    }
//    _titleView.frame = CGRectMake(0, 0, self.frame.size.width, 44);
//    [_titleView reloadView];
    return _titleView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *mainView = [[UIView alloc]init];
    mainView.frame = CGRectMake(0, 0, self.frame.size.width, 30);
    return mainView;
}
#pragma mark-得到上课点名列表
- (void)getShangkeDianmingRequest{
    NSDictionary *parama = @{@"tutorLessonId":@"1",
                             @"campusId":@"1",
                             @"classroomId":@"1",
                             @"tutorApplyIds":@"1"};
    [MBProgressHUD mj_showMessage:nil toView:self];
    [SYRequestAPI fd_TutorTutorClassServiceTutorLessonOffLineSign:parama success:^(id responseObject) {
       // NSLog(@"上课点名 %@",responseObject);
        [MBProgressHUD mj_hideHUDForView:self];
        [self->_tableList.mj_header endRefreshing];
        [self->_tableList.mj_footer endRefreshing];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self];
        [self->_tableList.mj_header endRefreshing];
        [self->_tableList.mj_footer endRefreshing];
    }];
}
@end
